<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <a-form-item label="批次名称">
              <a-input placeholder="请输入批次名称" v-model="queryParam.batchName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <a-form-item label="批次">
              <a-input placeholder="请输入批次" v-model="queryParam.batch"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="7" :lg="7" :md="8" :sm="24">
                <a-form-item label="创建时间">
                  <a-range-picker  format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']"  @change="onBirthdayChange" />
                </a-form-item>
              </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />批量删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange
        }"
        @change="handleTableChange"
      >
        <span slot="onOff" slot-scope="text">
          {{ text == 1 ? '开启' : '关闭' }}
        </span>
        <span slot="validTime" slot-scope="text, record">
          {{ text == 0 || text > 9999 ? '永久' : record.validTime }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="copy(record)">复制链接</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a @click="detailFormOk(record, '2')">修改</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="detailFormOk(record, '1')">详情</a>
              </a-menu-item>
              <!-- <a-menu-item>
                <a @click="Shares(record)">分享</a>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sharing-modal ref="detailForm" @ok="detailFormOk"></sharing-modal>
    <share-Modal ref="detailForm" @ok="detailFormOk"> </share-Modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import SharingModal from './modules/SharingModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction } from '../../../api/manage'
import shareModal from './modules/shareModal'
export default {
  name: 'BusTreviRiverPcList',
  mixins: [JeecgListMixin],
  components: {
    SharingModal,
    shareModal
  },
  data() {
    return {
      description: '分享资源',
      // 表头
      columns: [
        // {
        //   title: '批次名称',
        //   align: 'center',
        //   dataIndex: 'batchName'
        // },
        // {
        //   title: '批次',
        //   align: 'center',
        //   dataIndex: 'batch'
        // },
        {
          title: '密码开关',
          align: 'center',
          dataIndex: 'onOff',
          scopedSlots: { customRender: 'onOff' }
        },
        {
          title: '密码',
          align: 'center',
          dataIndex: 'password'
        },
        {
          title: '有效时间(天)',
          align: 'center',
          dataIndex: 'validTime',
          scopedSlots: { customRender: 'validTime' }
        },
        {
          title: '分享链接',
          align: 'center',
          dataIndex: 'url'
        },
        {
          title: '最后分享时间',
          align: 'center',
          dataIndex: 'effectiveSharingDate'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/shareInfo/shareInfo/list',
        delete: '/shareInfo/shareInfo/delete',
        deleteBatch: '/shareInfo/shareInfo/deleteBatch',
        exportXlsUrl: 'treviriverPc/busTreviRiverPc/exportXls',
        importExcelUrl: 'treviriverPc/busTreviRiverPc/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    //单个删除
    handleDelete(id) {
      const httpurl = this.url.delete
      const params = {
        id: id
      }
      deleteAction(httpurl, params).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    copy(record) {
      var input = document.createElement('input')
    
      input.setAttribute('value', record.url)
      document.body.appendChild(input)
      input.select()
      document.execCommand('copy')
      input.style.display = 'none'
      this.$message.success('复制成功可粘贴')
    }
    //分享
    // Shares(record)
    // {
    //   const batch = '3'
    //   const type = '1'
    //   this.$router.push(`/shareIndex?id=${record.id}&url=${record.url}&type=${type}&batch=${batch}`)
    // }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
